using System;
using System.Collections.Generic;
using System.Text;
using Arere.Core.Data;
using System.Data.SqlClient;

namespace Arere.Core.Data.SQLExpress
{
    public class ConcreteArea : AreaAdapter
    {
        SqlConnection connection;

        public ConcreteArea()
        {
            this.connection = new SqlConnection(
                Properties.Settings.Default.ConnectionString);
        }

        public override Area GetAreaById(Guid areaId)
        {
            Area area = null;
            SqlCommand command = new SqlCommand("AreaGetById",
                this.connection);
            command.CommandType = 
                System.Data.CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@AreaId", areaId));
            this.connection.Open();

            SqlDataReader reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                reader.Read();
                area = new Area(this, 
                    new Guid(reader["AreaId"].ToString()),
                    reader["Name"].ToString());
            }
            this.connection.Close();
            return area;
        }

        public override Area[] GetChildAreas(Guid areaId)
        {
            return null;
        }

        public override Area[] GetAdjacentAreas(Guid areaId)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override bool ChangeName(Guid areaId, string newName)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override Area CreateArea(string newName)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override bool AddChildArea(Guid parentId, Guid childId)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override bool RemoveChildArea(Guid parentId, Guid childId)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override bool AddAdjacentArea(Guid parentId, Guid adjacentId)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override bool RemoveAdjacentArea(Guid parentId, Guid adjacentId)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override bool RemoveArea(Guid areaId)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
